<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Insert title here</title>
  <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/lib/bootstrap/css/bootstrap.css" />
  <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/stylesheets/theme.css" />
  <link rel="stylesheet" href="${pageContext.request.contextPath}/static/lib/font-awesome/css/font-awesome.css" />
  <script src="${pageContext.request.contextPath}/static/lib/jquery-1.7.2.min.js" type="text/javascript"></script>
  <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/tooltips.js"></script>
</head>
<body>


<div id="menuDiv" class="sidebar-nav">

</div>
<script type="text/javascript">
  //一级菜单的名字    ->>对应的请求参数是parent
  var parent="${param.parent}";
  //二级菜单的名字   ->>>对应的请求参数是child
  var child="${param.child}";

  var menuArray=[
    {
      id:"book-menu",
      parent:"图书管理",
      icon:"icon-dashboard",
      childList:[
        {name:"查看图书信息",url:"${pageContext.request.contextPath}/BookManagerController/select"},
        {name:"添加图书信息",url:"${pageContext.request.contextPath}/AddBookController/forward"},
        {name:"回收站",url:"${pageContext.request.contextPath}/BookTrashController/select"}
      ]
    },
    {
      id:"ad-menu",
      parent:"促销管理",
      icon:"icon-dashboard",
      childList:[
        {name:"首页轮播",url:"${pageContext.request.contextPath}/ad/rotation"},
        {name:"公告板",url:"${pageContext.request.contextPath}/ad/adnews"}
      ]
    },
    {
      id:"type-menu",
      parent:"分类管理",
      icon:"icon-briefcase",
      childList:[
        {name:"分类列表管理",url:"${pageContext.request.contextPath}/type/typeView"}
      ]
    },
    {
      id:"order-menu",
      parent:"订单管理",
      icon:"icon-legal",
      childList:[
        {name:"订单列表",url:"${pageContext.request.contextPath}/OrderManagerController/select"},
        {name:"发货单列表",url:"${pageContext.request.contextPath}/OrderManagerController/reforwdOrderSend/1"},
        {name:"退货单列表",url:"${pageContext.request.contextPath}/OrderManagerController/reforawOrderReturns/1"}
      ]
    },
    {
      id:"account-menu",
      parent:"会员管理",
      icon:"icon-legal",
      childList:[
        {name:"查看会员信息",url:""},
        {name:"添加会员",url:""}
      ]
    }
  ];


  function loadMenu(){
    var str="<a href='${pageContext.request.contextPath}/' class='nav-header'><i class='icon-comment'></i>首页</a>";
    for(var i=0;i<menuArray.length;i++){
      var obj=menuArray[i];
      str+="<a href='#"+obj.id+"' class='nav-header' data-toggle='collapse'>";
      str+="<i class='"+obj.icon+"'></i>";
      str+=obj.parent;
      str+="</a>";
      str+="<ul id='"+obj.id+"' class='"+(parent==obj.parent?"nav nav-list collapse in":"nav nav-list collapse")+"'>";
      for(var j=0;j<obj.childList.length;j++){
        var childObj=obj.childList[j];
        str+="<li class='"+(child==childObj.name?"active":"")+"'><a href='"+childObj.url+"'>";
        str+=childObj.name;
        str+="</a></li>";
      }
      str+="</ul>";
    }

    $("#menuDiv").html(str);

    ////动态添加<script>标签////
    var scriptElement = document.createElement("script");
    scriptElement.src = "${pageContext.request.contextPath}/static/lib/bootstrap/js/bootstrap.js";
    $("body").append(scriptElement);
  }

  $(function(){
    loadMenu();
  });


</script>


<%--<script src="${pageContext.request.contextPath}/static/lib/bootstrap/js/bootstrap.js"></script>--%>
<%--<script type="text/javascript">--%>
<%--  toptal--%>
<%--</script>--%>

</body>
</html>
